package com.rpframework.module.common.bos.qiniu;

import com.qiniu.util.Auth;

/**
 * 七牛配置文件
 * Created by jump on 2016/8/23.
 */
public class Config {
    /**
     * 私钥
     */
    private String accessKey;
    /**
     * 密钥
     */
    private String secretKey;
    /**
     * 要上传的空间
     */
    private String bucketName;
    /**
     * 上传文件的路径
     */
    private String dowDomain;

    private Auth auth = null;

    private String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    private String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    private String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public String getDowDomain() {
        return dowDomain;
    }

    public void setDowDomain(String dowDomain) {
        this.dowDomain = dowDomain;
    }

    /**
     * 获取授权对象
     *
     * @return 授权对象
     */
    public Auth auth() {
        if (auth == null) auth = Auth.create(getAccessKey(), getSecretKey());
        return auth;
    }

    /**
     * 简单上传，使用默认策略，只需要设置上传的空间名就可以了
     */
    public String getUploadToken() {
        return auth().uploadToken(getBucketName());
    }
}
